package logic

import (
	"context"
	"math/rand"
	"strconv"
	"tiktok/model/redis"
	"tiktok/pkg"
	"time"

	"tiktok/rpc/internal/svc"
	"tiktok/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// ToDo:短信发送

func (l *SendSmsLogic) SendSms(in *pb.SendSmsReq) (*pb.SendSmsResp, error) {
	// todo: add your logic here and delete this line
	i := rand.Intn(900000) + 100000
	pkg.SendSms(in.Phone, strconv.Itoa(i))
	redis.Rdb.Set("send"+in.Source+in.Phone, i, time.Second*60*5)
	return &pb.SendSmsResp{}, nil
}
